<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增户型装修')"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-data">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" id="name" required>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">状态：</label>
            <div class="col-sm-8">
                <select class="form-control" name="status" th:with="items=${@dict.getType('sys_normal_disable')}">
                    <option th:each="dict : ${items}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js"/>
<script type="text/javascript">


    $(function () {

    });

    //配置表单验证规则
    $("#form-data").validate({
        onKeyup: false,
        rules: {
            name : {
                remote: {
                    url : ctx + "admin/house/renovation/exists",
                    type : "get",
                    dataType : "json",
                    data : {
                        "name": function () {
                            return $.common.trim($("#name").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "name": {
                remote: "该值已被占用"
            }
        },
        focusCleanup: true
    });

    //当按下弹出框的确定的时候
    function submitHandler() {
        //你的表单元素的值都验证通过了
        console.log("点击了确定按钮");
        if ($.validate.form()) {
            console.log("通过了验证");
            add();
        }
    }

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }

    function add() {

        //手工提交
        // var name = $("input[name='name']").val();
        // var status = $("input[id='status']").is(':checked') == true ? 0 : 1;

        var formDataString = $("#form-data").serialize();

        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "admin/house/renovation/add",
            data: formDataString,
            //同步
            async: false,
            dataType: 'json',
            error: function (request) {
                console.log(request);
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                console.log(data);
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>
